<?php
$d='.gx.cn';
$result_file='gx.domain.no';
$log='gx.domain.log';

$s2th=$s1th=array();
for ($i=0;$i<=9;$i++) {
    $s2th[]=$i;
}
for ($i=ord('a');$i<=ord('z');$i++) {
    $s2th[]=chr($i);
    $s1th[]=chr($i);
}
var_dump($s1th);
var_dump($s2th);
$domains = array();
foreach ($s1th as $s1) {
    foreach ($s2th as $s2) {
        $domains[] = $s1.$s2.$d;
    }
}
whoare($domains,$result_file,$log);

function whoare($domains,$result_file,$log,$callback=null) {
    foreach ($domains as $domain) {
        echo 'checking ',$domain," ... ";
        file_put_contents($log,$domain."----\n",FILE_APPEND);
        for ($i=0;$i<5;$i++) {
            $output = array();
            exec('whois '.$domain,$output,$ret);
            if ($ret===0 && count($output)>0) {
                break;
            }
            echo 'try ... ';
            sleep(1);
        }
        file_put_contents($log,implode("\n",$output)."\n",FILE_APPEND);
        if (count($output)<5 && strpos($output[0],'reserved')===false) {
            if ($callback) {
                $callback($domain);
            } else {
                file_put_contents($result_file,$domain."\n",FILE_APPEND);
            }
            echo "ok\n";
            foreach ($output as $o) {
                echo $o,"\n";
            }
        } else {
            echo "\r";
        }
        sleep(1);
    }
}
